package com.maila.xiaoaobusiness.api;

import android.content.Context;

import com.maila.xiaoaobusiness.net.NetWork;
import com.maila.xiaoaobusiness.net.VolleyInterface;
import com.maila.xiaoaobusiness.utils.Constants;

import java.io.File;
import java.util.HashMap;
import java.util.List;

/**
 * Created by mark on 2017/12/7.
 */

public class BusnissApi extends NetWork {

    public static final String URL_LOGIN = Constants.URL_ROOT_XIAOAO + "/index.php?ctrl=sellerlogo";
    public static final String URL_ACT = Constants.URL_ROOT_XIAOAO + "/index.php?ctrl=selleraction";
    public static final String URL_SHOP = Constants.URL_ROOT_XIAOAO + "/index.php?ctrl=sellershop";
    public static final String URL_GOODS = Constants.URL_ROOT_XIAOAO + "/index.php?ctrl=sellergoods";

    public BusnissApi(Context ctx, VolleyInterface listener) {
        super(ctx, listener);
    }

    public BusnissApi(Context ctx, VolleyInterface listener, String tag) {
        super(ctx, listener, tag);
    }

    /**
     * 用户登录
     *
     * @param username
     * @param pwd
     */
    public void login(String username, String pwd) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("username", username);
        query.put("password", pwd);
        requestPost(URL_LOGIN, "userlogin", query);
    }

    /**
     * 退出登录
     */
    public void logout() {
        requestGet(URL_LOGIN, "logout");
    }


    /**
     * 注册接口
     *
     * @param realname
     * @param carid
     * @param just_img
     * @param back_img
     * @param num      注册码
     * @param adcode
     */
    public void set_register(String realname, String phone, String pwd, String carid, String just_img, String back_img, String num, String adcode, String shopname, String business, String restaurant) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("realname", realname);
        query.put("phone", phone);
        query.put("num", num);
        query.put("password", pwd);
        query.put("card_id", carid);
        query.put("just_img", just_img);
        query.put("back_img", back_img);
        query.put("adcode", adcode);
        query.put("shopname", shopname);
        query.put("business", business);
        query.put("restaurant", restaurant);
        requestPost(URL_LOGIN, "register", query);
    }


//    店铺


    /**
     * 添加店铺分类
     *
     * @param typename
     */
    public void addClass(String typename) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("typename", typename);
        requestPost(URL_SHOP, "classify", query);
    }

    /**
     * 删除店铺分类
     *
     * @param typeid
     */
    public void delClass(String typeid) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("typeid", typeid);
        requestPost(URL_SHOP, "del_classify", query);
    }

    /**
     * 更新店铺分类
     *
     * @param typeid
     */
    public void updateClass(String typeid, String typename) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("typeid", typeid);
        query.put("typename", typename);
        requestPost(URL_SHOP, "update_classify", query);
    }

    /**
     * 获取所有分类
     */
    public void getclasslist() {
        requestGet(URL_SHOP, "classify_all");
    }

    /**
     * 分类排序
     *
     * @param sort 排序json  id ：1 ，orderid ：1
     */
    public void setclasssort(String sort) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("sort", sort);
        requestPost(URL_SHOP, "sort_classify", query);
    }

    /**
     * 修改店铺营业状态
     *
     * @param isopen
     */
    public void update_shop_status(int isopen) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("isopen", isopen);
        requestPost(URL_SHOP, "is_open", query);
    }

    /**
     * 获取店铺信息
     */
    public void getuserinfo() {
        requestGet(URL_SHOP, "information");
    }

    /**
     * 修改店铺信息
     *
     * @param notice_info
     * @param shopname
     * @param phone
     * @param phone
     * @param adcode
     */
    public void set_user_info(String img, String shopname, String phone, String address, String notice_info, String adcode, String shoplat, String shoplng) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("img", img);
        query.put("shopname", shopname);
        query.put("phone", phone);
        query.put("address", address);
        query.put("notice_info", notice_info);
        query.put("adcode", adcode);
        query.put("shoplat", shoplat);
        query.put("shoplng", shoplng);
        requestPost(URL_SHOP, "information", query);
    }


//    活动


    /**
     * 新建满减活动
     *
     * @param full
     * @param reduce
     * @param sendtime
     * @param endtime
     */
    public void add_act_manjian(String full, String reduce, String sendtime, String endtime) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("full", full);
        query.put("reduce", reduce);
        query.put("sendtime", sendtime);
        query.put("endtime", endtime);
        requestGet(URL_ACT, "reduce", query);
    }

    /**8
     * 修改满减活动
     * @param id
     * @param full
     * @param reduce
     * @param sendtime
     * @param endtime
     * @param addtime
     */
    public void update_act_manjian(String  id,String full, String reduce, String sendtime, String endtime,String  addtime) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("full", full);
        query.put("reduce", reduce);
        query.put("sendtime", sendtime);
        query.put("endtime", endtime);
        query.put("id", id);
        query.put("addtime", addtime);
        requestGet(URL_ACT, "update_reduce", query);
    }

    /**
     * 新建首单活动
     *
     * @param full
     * @param reduce
     * @param sendtime
     * @param endtime
     */
    public void add_act_shoudan(String full, String reduce, String sendtime, String endtime) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("full", full);
        query.put("reduce", reduce);
        query.put("sendtime", sendtime);
        query.put("endtime", endtime);
        requestGet(URL_ACT, "first_order", query);
    }

    /**
     * 修改首单活动
     * @param id
     * @param full
     * @param reduce
     * @param sendtime
     * @param endtime
     * @param addtime
     */
    public void update_act_shoudan(String  id,String full, String reduce, String sendtime, String endtime,String  addtime) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("full", full);
        query.put("reduce", reduce);
        query.put("sendtime", sendtime);
        query.put("endtime", endtime);
        query.put("id", id);
        query.put("addtime", addtime);
        requestGet(URL_ACT, "update_first_order", query);
    }

    /**
     * 新增 今日特价活动
     * @param goodsid
     * @param zhe
     * @param num
     */
    public void add_act_today(String  goodsid,String zhe, String num) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("goodsid", goodsid);
        query.put("zhe", zhe);
        query.put("num", num);
        requestGet(URL_ACT, "day_tejia", query);
    }

    /**
     * 修改 今日特价活动
     * @param goodsid_old
     * @param goodsid_new
     * @param zhe
     * @param num
     * @param addtime
     */
    public void update_act_today(String goodsid_old,String  goodsid_new,String zhe, String num,String  addtime) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("goodsid_old", goodsid_old);
        query.put("zhe", zhe);
        query.put("num", num);
        query.put("goodsid_new", goodsid_new);
        query.put("addtime", addtime);
        requestGet(URL_ACT, "update_day_tejia", query);
    }

    /**
     * 新增折扣活动
     * @param goodsid
     * @param zhe
     * @param num
     * @param sendtime
     * @param endtime
     */
     public void add_act_promotion(String goodsid,String zhe, String num, String sendtime, String endtime) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("goodsid", goodsid);
        query.put("zhe", zhe);
        query.put("num", num);
        query.put("sendtime", sendtime);
        query.put("endtime", endtime);
        requestGet(URL_ACT, "promotion", query);
    }

    /**
     * 编辑折扣活动
     * @param goodsid_new
     * @param goodsid_old
     * @param addtime
     * @param zhe
     * @param num
     * @param sendtime
     * @param endtime
     */
    public void update_act_promotion(String goodsid_new,String goodsid_old,String addtime,String zhe, String num, String sendtime, String endtime) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("zhe", zhe);
        query.put("num", num);
        query.put("sendtime", sendtime);
        query.put("endtime", endtime);
        query.put("goodsid_new", goodsid_new);
        query.put("goodsid_old", goodsid_old);
        query.put("addtime", addtime);
        requestGet(URL_ACT, "update_promotion", query);
    }

    /**
     * 新建返券活动
     *
     * @param full
     * @param sendtime
     * @param endtime
     */
    public void add_act_fanquan(String full, String sendtime, String endtime) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("full", full);
        query.put("sendtime", sendtime);
        query.put("endtime", endtime);
        requestGet(URL_ACT, "fanquan", query);
    }

    /**
     *修改下单返券活动
     * @param id
     * @param full
     * @param sendtime
     * @param endtime
     * @param addtime
     */
    public void add_act_fanquan(String id,String full, String sendtime, String endtime,String addtime) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("id", id);
        query.put("full", full);
        query.put("sendtime", sendtime);
        query.put("endtime", endtime);
        query.put("addtime", addtime);
        requestGet(URL_ACT, "update_fanquan", query);
    }
    /**
     * 添加优惠券
     *
     * @param full
     * @param reduce
     * @param sendtime
     * @param endtime
     */
    public void add_coupon(String full, String reduce, String sendtime, String endtime) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("full", full);
        query.put("reduce", reduce);
        query.put("sendtime", sendtime);
        query.put("endtime", endtime);
        requestGet(URL_ACT, "coupon", query);
    }

    /**
     * 编辑优惠券
     *
     * @param id
     * @param full
     * @param reduce
     * @param sendtime
     * @param endtime
     */
    public void update_coupon(String id, String full, String reduce, String sendtime, String endtime) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("full", full);
        query.put("quanid", id);
        query.put("reduce", reduce);
        query.put("sendtime", sendtime);
        query.put("endtime", endtime);
        requestGet(URL_ACT, "coupon", query);
    }

    /**
     * 删除满减活动
     *
     * @param ruleid
     */
    public void delManjian(String ruleid) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("ruleid", ruleid);
        requestPost(URL_ACT, "del_reduce", query);
    }

    /**
     * 删除首单活动
     *
     * @param ruleid
     */
    public void delShoudan(String ruleid) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("ruleid", ruleid);
        requestPost(URL_ACT, "del_first_order", query);
    }

    /**
     * 删除今日特价活动
     * @param goodsid
     */
    public void delTodayprice(String goodsid) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("goodsid", goodsid);
        requestPost(URL_ACT, "del_first_order", query);
    }
    public void delpromotion(String goodsid) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("goodsid", goodsid);
        requestPost(URL_ACT, "del_promotion", query);
    }

    /**
     * 删除返券活动
     *
     * @param ruleid
     */
    public void delFanquan(String ruleid) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("ruleid", ruleid);
        requestPost(URL_ACT, "del_fanquan", query);
    }

    /**
     * 删除优惠券
     *
     * @param quanid
     */
    public void delCoupon(String quanid) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("quanid", quanid);
        requestPost(URL_ACT, "del_coupon", query);
    }

    /**
     *获取满减活动列表
     */
    public void getact_manjianlist() {
        requestGet(URL_ACT, "manjian_list");
    }
    /**
     *获取首单立减活动列表
     */
    public void getact_firstorderlist() {
        requestGet(URL_ACT, "first_order_list");
    }
    /**
     *获取今日特价活动列表
     */
    public void getact_todaypricelist() {
        requestGet(URL_ACT, "day_tejia_list");
    }
    /**
     *获取折扣活动列表
     */
    public void getact_promotionlist() {
        requestGet(URL_ACT, "promotion_list");
    }
    /**
     *获取下单返券活动列表
     */
    public void getact_fanquanlist() {
        requestGet(URL_ACT, "fanquan_list");
    }

//商品

    /**
     * 添加新商品
     *
     * @param goodsname
     * @param typeid    分类id
     * @param img
     * @param cost      价格
     * @param bagcost   打包费 包装费用
     * @param goodsattr 单位
     * @param count     数量
     */
    public void add_good(String goodsname, String typeid, String img, String cost, String bagcost, String goodsattr, String count) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("goodsname", goodsname);
        query.put("typeid", typeid);
        query.put("img", img);
        query.put("cost", cost);
        query.put("bagcost", bagcost);
        query.put("goodsattr", goodsattr);
        query.put("count", count);
        requestPost(URL_GOODS, "new_goods", query);
    }

    /**
     * 更新商品信息
     *
     * @param goodsid
     * @param goodsname
     * @param typeid
     * @param img
     * @param cost
     * @param bagcost
     * @param goodsattr
     * @param count
     */
    public void update_good(String goodsid, String goodsname, String typeid, String img, String cost, String bagcost, String goodsattr, String count) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("goodsid", goodsid);
        query.put("goodsname", goodsname);
        query.put("typeid", typeid);
        query.put("img", img);
        query.put("cost", cost);
        query.put("bagcost", bagcost);
        query.put("goodsattr", goodsattr);
        query.put("count", count);
        requestPost(URL_GOODS, "update_goods", query);
    }

    /**
     * 删除商品
     * @param goodsid
     */
    public void del_goods(String goodsid) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("goodsid", goodsid);
        requestPost(URL_GOODS, "del_goods", query);
    }
    /**
     * 更新商品状态
     *
     * @param goodsid
     * @param islive  0 下架 1 上架
     */
    public void set_goods_status(String goodsid, int islive) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("goodsid", goodsid);
        query.put("islive", islive);
        requestPost(URL_GOODS, "down_goods", query);
    }

    /**
     * 获取商品分类列表 及商品列表
     */
    public void get_classify_goods_list(){
    requestGet(URL_GOODS, "shop_classify");
}

//    订单

    /**
     * 未完成订单
     *
     * @param page
     * @param size
     */
    public void get_unfinished_order_list(int page, int size, String adcode) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        query.put("adcode", adcode);
        requestGet(URL_LOGIN, "unfinished_order", query);
    }

    /**
     * 抢单大厅列表
     *
     * @param page
     * @param size
     * @param adcode
     */
    public void get_all_order_list(int page, int size, String adcode) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        query.put("adcode", adcode);
        requestGet(URL_LOGIN, "orders", query);
    }

    /**
     * 个人主页
     * 个人主页
     */
    public void getmy_evaluate() {
        requestGet(URL_LOGIN, "my_evaluate", null);
    }

    /**
     * 获取配送地址列表
     *
     * @param page
     * @param size
     */
    public void get_address_list(int page, int size, String adcode) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        query.put("adcode", adcode);
        requestGet(URL_LOGIN, "address", query);
    }

    /**
     * 接单
     *
     * @param type 1.跑腿—取件
     *             2.跑腿—快递
     *             3.外卖
     */
    public void get_order(String id, int type) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("orderid", id);
        query.put("type", type);
        requestPost(URL_LOGIN, "grab_order", query);
    }

    /**
     * 取货
     *
     * @param type 1 取件 2 快递 3  外卖
     */
    public void order_pickup(String orderid, int type) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("orderid", orderid);
        query.put("type", type);
        requestPost(URL_LOGIN, "wai_pickup", query);
    }

    /**
     * 完成外卖
     *
     * @param orderid
     */
    public void complete_waimai(String orderid) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("orderid", orderid);
        query.put("type", "3");
        requestPost(URL_LOGIN, "wai_finish", query);

    }

    /**
     * 完成跑腿
     *
     * @param orderid
     * @param type
     */
    public void complete_paotui(String orderid, int type) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("orderid", orderid);
        query.put("type", type);
        requestPost(URL_LOGIN, "pao_finish", query);

    }

    /**
     * 设置快递金额
     *
     * @param orderid
     * @param weight
     * @param cost
     */
    public void set_pao_fee(String orderid, String weight, String cost) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("orderid", orderid);
        query.put("weight", weight);
        query.put("cost", cost);
        requestPost(URL_LOGIN, "pao_finish", query);

    }


    /**
     * 上传单张图片
     *
     * @param filepartname
     * @param file
     */
    public void uploadimg(String filepartname, File file) {
        uploadOneImg(URL_LOGIN, "update_address", null, filepartname, file);
    }

    /**
     * 上传多张图片
     *
     * @param filepartname
     * @param file
     */
    public void uploadmultimg(String filepartname, List<File> file) {
        uploadMutiImg(URL_LOGIN, "update_address", null, filepartname, file);
    }

}
